{template admin/header}
<script src="static/js/date/WdatePicker.js" type="text/javascript"></script>
<script type="text/javascript">
    function checkinput() {
        if (document.getElementById('username').value == '') {
            MessageBox('notice', "请选择用户", '提示');
            return false;
        }
        if (Number(document.getElementById('amount').value) == '') {
            MessageBox('notice', "红包总额必须大于1", '提示');
            return false;
        }
        if (Number(document.getElementById('num').value) == 0) {
            MessageBox('notice', "红包个数大于1", '提示');
            return false;
        }
        var amount = Number(document.getElementById('amount').value);
        var num = Number(document.getElementById('num').value);
        console.log(amount);
        console.log(num);
        if(amount < num){
            MessageBox('notice', "红包个数不能大于红包总额", '提示');
            return false;
        }
        var num = document.getElementById('num').value;
        if(act_type == '0'){
            if(amount%num != 0){
                MessageBox('notice', "红包不能整除", '提示');
                return false;
            }
        }
        if (document.getElementById('stime').value == '') {
            MessageBox('notice', "请输入开始时间", '提示');
            return false;
        }
        if (document.getElementById('etime').value == '') {
            MessageBox('notice', "请输入结束时间", '提示');
            return false;
        }
        if (document.getElementById('etime').value <= document.getElementById('stime').value) {
            MessageBox('notice', "结束时间必须大于开始时间", '提示');
            return false;
        }
    }
    
</script>
<div class="mt10">
<style type="text/css">
    .radio_uid{margin: 10px;}
</style>
    <form action="{$action}" method="post" enctype="multipart/form-data" name="form1" id="form1" onsubmit="return checkinput()">
        <table cellspacing="1" cellpadding="4" width="100%" align="center" class="tableborder">
            <tr class="header">
                <td colspan="2">{$title}</td>
            </tr>
            <tr>
                <td width="13%" bgcolor="#F8F8F8">&nbsp;</td>
                <td width="87%" bgcolor="#FFFFFF">&nbsp;</td>
            </tr>
            <tr>
                <td width="13%" bgcolor="#F8F8F8">搜索用户</td>
                <td bgcolor="#FFFFFF">
                    <input id="username" type="text" value="" name="username">
                    <input id="check_PublishBox_uid" type="hidden" value="" name="check_PublishBox_uid">
                    <input type="submit" class="adminTopsearchbutton" name="usernamesubmit" value="搜索">
                </td>
            </tr>
            <tr>
                <td width="13%" align="center" bgcolor="#F8F8F8">用户：</td>
                <td bgcolor="#FFFFFF" id="users">
                    
                </td>
            </tr>
            <tr>
                <td width="13%" bgcolor="#F8F8F8">红包类型</td>
                <td width="87%" align="right" bgcolor="#FFFFFF">
                    <select id="act_type" name="act_type">
                        <option value="0">普通红包</option>
                        <option value="1">拼手气</option>
                    </select>
                </td>
            </tr>
            <tr>
                <td class="altbg1" width="13%" bgcolor="#F8F8F8">描述</td>
                <td class="altbg2" width="87%" align="right" bgcolor="#FFFFFF">
                    <input type="text" id="title" name="title">
                </td>
            </tr>
            <tr>
                <td class="altbg1" width="13%" bgcolor="#F8F8F8">红包总额</td>
                <td class="altbg2" width="87%" align="right" bgcolor="#FFFFFF">
                    <input type="text" id="amount" name="amount" maxlength="30">
                </td>
            </tr>
            <tr>
                <td class="altbg1" width="13%" bgcolor="#F8F8F8">红包个数</td>
                <td class="altbg2" width="87%" align="right" bgcolor="#FFFFFF">
                    <input type="text" id="num" name="num" maxlength="30">(必须保证最小红包不能小于1)
                </td>
            </tr>
            <tr>
                <td class="altbg1" width="15%" bgcolor="#F8F8F8">开始时间</td>
                <td class="altbg2" width="85%" align="right" bgcolor="#FFFFFF">
                    <input type="text" id="stime" name="stime" readonly="readonly" class="Wdate" onClick="WdatePicker({dateFmt: 'yyyy-MM-dd  HH:mm'});">
                </td>
            </tr>
            <tr>
                <td class="altbg1" width="15%" bgcolor="#F8F8F8">结束时间</td>
                <td class="altbg2" width="85%" align="right" bgcolor="#FFFFFF">
                    <input type="text" id="etime" name="etime" readonly="readonly" class="Wdate" onClick="WdatePicker({dateFmt: 'yyyy-MM-dd  HH:mm'});">（必须输入，即：超过该时间后，自动下架。）
                </td>
            </tr>		
            <tr>
                <td class="altbg1" width="13%" bgcolor="#F8F8F8">是否开启</td>
                <td class="altbg2" width="87%" align="right" bgcolor="#FFFFFF">
                    <input id="radio" value="1" checked="checked" type="radio" name="status" />开启
                    <input id="radio" value="0" type="radio" name="status" />关闭
                </td>
            </tr>
        </table>
        <br>
        <center><input type="submit" class="button" id="submit" name="addsubmit" value="保 存"></center>

    </form>

</div>
<script type="text/javascript">
    $(function() {
        $("input[name=usernamesubmit]").click(function() {
            var username = $("input[name=username]").val();
            $.post("ajax.php?mod=member&code=select_nickname", {
                nickname: username
                },
                function(ret) {
                    var json = $.parseJSON(ret);
                    if(json && json.done){
                        var list = json.retval;
                        var html = '';
                        for (var i = 0, len = list.length; i < len; i++) {
                            var data = list[i];
                            html += '<input type="radio" class="radio_uid" name= "radio_uid" value="'+data.uid+'" />'+data.nickname;
                        }
                        $("#users").html(html);
                        radio_check();
                    }
                }
            );
            return false;
        });
        function radio_check(){
            $("#users").find("input[name=radio_uid]").click(function(){
                var uid = $(this).val();
                $("#check_PublishBox_uid").val(uid);
                
            });
        }
        
    })
</script>
